home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
dax1.exe
/
CLIENT
/
INOUT
/
NLM
/
INOUT.C
next >
Wrap
Text File
|
1992-07-15
|
5KB
|
147 lines
// ╔════════════════════════════════════════════════════════════════════╗
// ║ ║
// ║ module: inout.c ║
// ║ abstract: This module logs in and out of the DAP Engine. ║
// ║ This NLM version can spawn multiple clients, threads, ║
// ║ which can really test 'race' conditions. ║
// ║ ║
// ║ environment: NetWare 3.x v3.11 ║
// ║ Network C for NLMs SDK ║
// ║ CLib v3.11 ║
// ║ ║
// ║ This software is provided as is and carries no warranty ║
// ║ whatsoever. Novell disclaims and excludes any and all implied ║
// ║ warranties of merchantability, title and fitness for a particular ║
// ║ purpose. Novell does not warrant that the software will satisfy ║
// ║ your requirements or that the software is without defect or error ║
// ║ or that operation of the software will be uninterrupted. You are ║
// ║ using the software at your risk. The software is not a product ║
// ║ of Novell, Inc. or any of subsidiaries. ║
// ║ ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ maintenance history: ║
// ║ level date pi description ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ 001 03/05/92 kl initial release. ║
// ╚════════════════════════════════════════════════════════════════════╝
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <nwsemaph.h>
#include "h/appl.h"
#include "dap/dapapi.h"
LONG semaIOHandle;
myprintf(int threadnum, int offset, char *msg)
{
if( semaIOHandle ) WaitOnLocalSemaphore(semaIOHandle);
gotoxy((threadnum % 3) * 25 + offset, threadnum / 3);
while(*msg) putch(*msg++);
if( semaIOHandle ) SignalLocalSemaphore(semaIOHandle);
}
threadputch(int threadnum, int offset, char byte)
{
char data[] = "?";
*data = byte;
myprintf(threadnum,offset,data);
}
errorexit(int threadnum, int rc, char *msg, DAPDATA *dd)
{
char buf[255];
sprintf(buf, "%s:%s",
msg,
DAPTranslateReturnCode(rc));
myprintf(threadnum, 0, buf);
if( dd ){
DAPDisplaySessionData(dd);
DAPDeInitialize(dd);
}
ExitThread(EXIT_THREAD,1);
}
s_atexit()
{
if( semaIOHandle ) CloseLocalSemaphore(semaIOHandle);
}
#define threadAtSay(threadnum, msg) myprintf(threadnum,0,msg)
#define threadprint(threadnum,offset, msg) myprintf(threadnum,offset,msg)
#define DEFOUTER 1000
#define DEFINNER 10
LONG outerlimit = DEFOUTER;
LONG innerlimit = DEFINNER;
WorkerThread(void *_threadNum)
{
int rc,x,y;
int offset;
LONG iter=0L;
char junk[10];
DAPDATA *dd;
int threadNum = (int)_threadNum;
for(x=0; !kbhit() && x < outerlimit; ++x){
for(y=1; !kbhit() && y < innerlimit; ++y){
offset = 0;
threadputch(threadNum, offset++,'i');
if( (dd = DAPInitialize(SERVERNAME, SERVERTYPE)) == NULL ){
threadAtSay(threadNum,"Could not initialize");
ExitThread(EXIT_THREAD,1);
}
threadputch(threadNum, offset++,'a');
if( (rc = DAPAllocateSession(dd)) != NULL ){
errorexit(threadNum,rc,"AS",dd);
}
threadputch(threadNum, offset++,'d');
sprintf(junk,"%04d",*(long *)&(((int *)dd)[1]));
threadprint(threadNum,offset,junk);
offset += 4;
if( (rc = DAPDeAllocateSession(dd)) != NULL ){
errorexit(threadNum,rc,"DA",dd);
}
threadputch(threadNum, offset++,'u');
DAPDeInitialize(dd);
threadprint(threadNum,0,"........");
dd = NULL;
++iter;
}
}
ExitThread(EXIT_THREAD,0);
}
main(int argc, char *argv[])
{
int numclients;
int threadNum=0;
if( argc < 2 ){
printf("usage: inout <numClients> [outer] [inner]\n");
exit(1);
}
atexit(s_atexit);
semaIOHandle = OpenLocalSemaphore(1);
numclients = atoi(argv[1]);
if( argc == 4 ){
outerlimit = atoi(argv[2]);
innerlimit = atoi(argv[3]);
}
while( numclients-- ){
if(BeginThreadGroup(WorkerThread,NULL,8192,(void *)threadNum) == EFAILURE){
threadAtSay(threadNum,"Failed to start");
exit(1);
}
threadNum++;
ThreadSwitch();
}
return 0;
}